/**
 * 上海中赢金融信息服务有限公司
 * Copyright (c) 2017-2027 Chinazyjr,Inc.All Rights Reserved.
 */
package com.sys.midware.hbase.hcore.filter;

/**
 * hbaseFilterFactory <b>ClassName：</b> HbaseFilterFactory <br/>
 * <b>Description：</b> TODO <br/>
 * <b>@author：</b> mobing <br/>
 * <b>@date：</b> 2015年10月26日 下午7:47:37 <br/>
 * <b>@version: </b> <br/>
 */
public class HbaseFilterFactory {

    /**
     * 创建列(列包含列族,列和列值)的过滤器
     * 
     * @param family  列族名
     * @param qualifier 列名
     * @param value 列值
     * @param op 比较操作符
     * @return
     */
    public static HbaseFilter createSingleColumnValueFilter(String family, String qualifier, Object value, CompareOp op) {
        return new SingleColumnValueFilter(family, qualifier, value, op);
    }

    /**
     * 创建rowKey的过滤器
     * 
     * @param value
     * @param op
     * @param comparator
     * @return
     */
    public static HbaseFilter createRowFilter(Object value, CompareOp op, Comparator comparator) {
        return new RowFilter(value, op, comparator);
    }
    /**
     * 比较操作符
     * <b>@author：</b> mobing <br/>
     * <b>@date：</b> 2016年1月6日 下午2:32:16 <br/>
     * <b>@version: </b>  <br/>
     */
    public static enum CompareOp {
        EQUAL, GREATER, GREATER_OR_EQUAL, LESS, LESS_OR_EQUAL, NO_OP, NOT_EQUAL,
    };

    public static enum Comparator {
        BINARY, REGEX_STRING, SUB_STRING, BINARY_PREFIX, BIT, NULL
    };

    //
   public static class SingleColumnValueFilter implements HbaseFilter {
        private String family;

        private String qualifier;

        private Object value;

        private CompareOp op;

        private Comparator comparator;

        public SingleColumnValueFilter(String family, String qualifier, Object value, CompareOp op,
                Comparator comparator) {
            super();
            this.family = family;
            this.qualifier = qualifier;
            this.value = value;
            this.op = op;
            this.comparator = comparator;
        }

        public SingleColumnValueFilter(String family, String qualifier, Object value, CompareOp op) {
            this(family, qualifier, value, op, null);
        }

        public String getFamily() {
            return family;
        }

        public String getQualifier() {
            return qualifier;
        }

        public Object getValue() {
            return value;
        }

        public CompareOp getOp() {
            return op;
        }

        public Comparator getComparator() {
            return comparator;
        }

    }

  public  static class RowFilter implements HbaseFilter {
        private Object value;

        private CompareOp op;

        private Comparator comparator;

        public RowFilter(Object value, CompareOp op, Comparator comparator) {
            super();
            this.value = value;
            this.op = op;
            this.comparator = comparator;
        }

        public Object getValue() {
            return value;
        }

        public void setValue(Object value) {
            this.value = value;
        }

        public CompareOp getOp() {
            return op;
        }

        public void setOp(CompareOp op) {
            this.op = op;
        }

        public Comparator getComparator() {
            return comparator;
        }

        public void setComparator(Comparator comparator) {
            this.comparator = comparator;
        }

        @Override
        public String getFamily() {
            return null;
        }

        @Override
        public String getQualifier() {
            return null;
        }

    }

}
